﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class delete : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CGeneral.CheckLogin(Request, Session);

        Permission per = new Permission(int.Parse(Session["gid"].ToString()));
        if (per.awmag == 0)
            CGeneral.GoToErrorPage(Response, "custom", "YOU NEED MORE POWER");
        if (Request.QueryString["type"] == "topic")
        {
            if (Request.QueryString["tid"] != null && Request.QueryString["fid"] != null)
            {
               
                //效验
                int tid = Check.CheckToInt(Request.QueryString["tid"]);
                int fid = Check.CheckToInt(Request.QueryString["fid"]);
                if (tid == -1 || fid == -1)
                    CGeneral.GoToErrorPage(Response, "custom", "参数错误");

                //begin 删除主题
                Topic.Del(tid);

                //end
                Response.Redirect("forum.aspx?fid="+fid+"&page=1");

            }
        }
        else if (Request.QueryString["type"] == "reply")
        {
           if (Request.QueryString["tid"] != null && Request.QueryString["pid"] != null && Request.QueryString["page"] != null)
           {
               int pid = Check.CheckToInt(Request.QueryString["pid"]);
               int tid = Check.CheckToInt(Request.QueryString["tid"]);
               int page = Check.CheckToInt(Request.QueryString["page"]);
               
               if(tid==-1||tid==-1||page==-1)
                   CGeneral.GoToErrorPage(Response, "custom", "参数错误");
               //begin 删除回复
               Reply.Del(pid);
               //end
               Response.Redirect("ViewTopic.aspx?tid=" + tid + "&page=" + page);
           }
        }
        else if (Request.QueryString["type"] == "user")
        {
            if(Request.QueryString["uid"]!=null)
            {
                int uid = Check.CheckToInt(Request.QueryString["uid"]);
                if(uid==-1)
                    CGeneral.GoToErrorPage(Response, "custom", "参数错误");
                SaveData.DelMember(uid);
                Response.Redirect("Admin.aspx?type=member");
            }

            
        }
        else if (Request.QueryString["type"] == "forum")
        {

            if (Request.QueryString["fid"] != null)
            {
                int fid = Check.CheckToInt(Request.QueryString["fid"]);
                if (fid == -1)
                    CGeneral.GoToErrorPage(Response, "custom", "参数错误");
                SaveData.ToggleForum(fid);
                Response.Redirect("Admin.aspx?type=forum");
            }
        }


        CGeneral.GoToErrorPage(Response, "ParamWrong");
    }
}